<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Category;
use common\models\Docstatus;
use common\models\Lockstatus;
use yii\grid\Column;
/* @var $this yii\web\View */
/* @var $searchModel common\models\DocSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="doc-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            // ['class' => 'yii\grid\SerialColumn'],

            'did',

			'title',
            // 'cid',
        	['attribute'=>'cid',
        	'label'=>'分类',
        	'value'=>'category.name',
            'filter'=>Category::find()
            		->select(['name','cid'])
            		->orderBy('docnum')
            		->indexBy('cid')
            		->column(),			
  				
    		],		
            
            'keywords:ntext',
            // 'summary:ntext',

            // 'content:ntext',
            // 'authorname',
            // 'time:datetime',
            // 'lastedit',
			'lasteditorname',
             ['attribute'=>'lastedit',
             'format'=>['date','php:Y-m-d H:i:s'],
        	],
             			
            
            // 'viewnum',
            // 'hisedition:ntext',
            // 'status',
            ['attribute'=>'status',
            'value'=>'status0.name',
            'filter'=>Docstatus::find()
            		->select(['name','id'])
            		->orderBy('position')
            		->indexBy('id')
            		->column(),
            'contentOptions'=>
            		function($model)
            		{
            			return ($model->status==1)?['class'=>'bg-danger']:[];
            		}					
   			 ],
            // 'create_time:			
            // 'locked',
        	['attribute'=>'locked',
        	'label'=>'是否锁定',
        	'value'=>'lockstatus0.name',
            'filter'=>Lockstatus::find()
            		->select(['name','id'])
            		->orderBy('position')
            		->indexBy('id')
            		->column(),	
            'contentOptions'=>
            		function($model)
            		{
            			return ($model->locked==2)?['class'=>'bg-warning']:[];
            		}					
    		],	
            ['class' => 'yii\grid\ActionColumn',
            'template'=>'{view} {delete} {approve} {lock}',
            'buttons'=>
            	[
            	'approve'=>function($url,$model,$key)
            			{
            				$options=[
            					'title'=>Yii::t('yii', '审核'),
            					'aria-label'=>Yii::t('yii','审核'),
            					'data-confirm'=>Yii::t('yii','你确定通过该词条吗？'),
            					'data-method'=>'post',
            					'data-pjax'=>'0',
            						];
            				return Html::a('<span class="glyphicon glyphicon-check"></span>',$url,$options);
            				
            			},
           	    'lock'=>function($url,$model,$key)
            			{
            				$options=[
            					'title'=>Yii::t('yii', '锁定'),
            					'aria-label'=>Yii::t('yii','锁定'),
            					'data-confirm'=>Yii::t('yii','你确定锁定该词条吗？'),
            					'data-method'=>'post',
            					'data-pjax'=>'0',
            						];
            				return Html::a('<span class="glyphicon glyphicon-lock"></span>',$url,$options);
            				
            			},						
            	],	
             // 'headerOptions' => ['width' => '100'],				
			],
        ],
    ]); ?>
</div>
